package leetcode;


import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Collectors;

public class Lc179 {

    public String largestNumber(int[] nums) {
        String[] strs = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs, ((o1, o2) -> new StringBuilder(o2).append(o1).toString().compareTo(new StringBuilder(o1).append(o2).toString())));
        String ans = Arrays.stream(strs).collect(Collectors.joining());
        return ans.toString().startsWith("0") ? "0" : ans.toString(); //如果有前导0，那么所有的字符都是0，如果有其他数字，0不会排在最前面
    }

    public static void main(String[] args) {
        Lc179 lc179 = new Lc179();
        System.out.println(lc179.largestNumber(new int[]{0,0}));

        System.out.println("0000".replaceAll("^0*", "0"));
    }

}
